<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<!--
<script src="http://www.google.com/jsapi?key=ABQIAAAANU8OAqbJPAHXV4SpKuTEvhQx6TWrfC8bNfnC-vtzzHJYkwhD6xSt50-Z_44EojojRLDiBj3kn932Rw" type="text/javascript"></script>
-->


<title>gcal test</title>

<script type="text/javascript" src="jquery.js"></script>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script src="jquery.googlecalreader-1.0.js" type="text/javascript"></script>

<script type="text/javascript">
google.load("gdata", "2.x", {packages: ["calendar"]});
google.setOnLoadCallback(_doCalendar);


function _doCalendar() {
  var feedUrl = "https://www.google.com/calendar/feeds/u6g675oejpdha4pncv50rmi8tc%40group.calendar.google.com/public/basic";
  var calendarService = new google.gdata.calendar.CalendarService('LiquidChicken-jsWotdStandAlone-1.0');
  var query = new google.gdata.calendar.CalendarEventQuery(feedUrl);
  var maxResults = 10;
  var displayCount = 1;

  query.setOrderBy('starttime');
  query.setSortOrder('ascending');
  query.setFutureEvents(true);
  query.setSingleEvents(true);
  query.setMaxResults(maxResults);

  var callback = function (result) {
      var entries = result.feed.getEntries();
      $('#gcal').html('');
      if (displayCount) {
          $('#gcal').html(entries.length + ' upcoming events');
      }
      $('#gcal').append('<ul id="eventlist"></ul>');

      for (var i = 0; i < entries.length; i++) {
          var eventEntry = entries[i];
          var eventTitle = eventEntry.getTitle().getText();
          var startDateTime = null;
          var eventDate = null;
          var eventWhere = null;
          var eventContent = eventEntry.getContent().getText();

          var times = eventEntry.getTimes();
              if (times.length > 0) {
                  startDateTime = times[0].getStartTime();
                  eventDate = startDateTime.getDate();
              }

              var d_names = new Array("Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat");
              var m_names = new Array("Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec");

              var a_p = "";
              var d = eventDate;
              var curr_hour = d.getHours();
              if (curr_hour < 12) {
                  a_p = "am";
              }
              else {
                  a_p = "pm";
              }
              if (curr_hour == 0) {
                  curr_hour = 12;
              }
              if (curr_hour > 12) {
                  curr_hour = curr_hour - 12;
              }

              var curr_min = d.getMinutes();
              curr_min = curr_min + "";

              if (curr_min.length == 1) {
                  curr_min = "0" + curr_min;
              }

              var time = curr_hour + ':' + curr_min + a_p;
              var day = eventDate.getDay();
              var month = eventDate.getMonth();
              var date = eventDate.getDate();
              var dayname = d_names[day];
              var monthname = m_names[month];
              var location = eventEntry.getLocations();
              var eventWhere = location[0].getValueString();

              var eventhtml = '<div id="eventtitle">' + eventTitle + '</div>  When: ' + dayname + ' ' + monthname + ' ' + date + ', ' + time + '<br>Where: ' + eventWhere + '<br>' + eventContent;
              $('#eventlist').append('<li>' + eventhtml + '</li>');
      }
  };

  // Error handler to be invoked when getEventsFeed() produces an error
  var handleError = function (error) {
      $('#gcal').html('<pre>' + error + '</pre>');
  };


  // Submit the request using the calendar service object
  calendarService.getEventsFeed(query, callback, handleError);
}

</script>
</head>
<body>
<img src="/~ksetzer/images/blank.gif" style="position:absolute; top: -1000px;"/>

<div id="wotdList"/>

<hr>
<div id="gcal"/"

</body>
</html>


